package com.xxx.video.mine.adapters;

import android.content.Context;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;

import com.bumptech.glide.Glide;
import com.bumptech.glide.request.RequestOptions;
import com.xxx.video.R;
import com.xxx.video.commen.adapters.BaseRecycleViewAdapter;
import com.xxx.video.commen.adapters.BaseViewHolder;
import com.xxx.video.commen.utils.ResourcesUtils;
import com.xxx.video.commen.utils.StringUtils;
import com.xxx.video.dynamic.beans.FriendListBean;
import com.xxx.video.mine.beans.SearchResultListBean;

import butterknife.BindView;

public class SearchFriendResultListAdapter extends BaseRecycleViewAdapter<SearchResultListBean.ListBean, SearchFriendResultListAdapter.MyHolder> {


    public SearchFriendResultListAdapter(@NonNull Context context) {
        super(context);
    }

    @Override
    public MyHolder onCreateDefaultViewHolder(View view, int viewType) {
        return new MyHolder(view);
    }


    @Override
    public int getItemLayout(int viewType) {
        return R.layout.item_find_friend_result_list;
    }

    public void addFriendSuccess(int position) {
        data.get(position).fStatus="0";
        notifyDataSetChanged();
    }

    class MyHolder extends BaseViewHolder {
        @BindView(R.id.iv_item_find_friend_result_list_avatar)
        ImageView ivItemFindFriendResultListAvatar;
        @BindView(R.id.tv_item_find_friend_result_list_name)
        TextView tvItemFindFriendResultListName;
        @BindView(R.id.tv_item_find_friend_result_list_add)
        TextView tvItemFindFriendResultListAdd;
        @BindView(R.id.tv_item_find_friend_result_list_status)
        TextView tvItemFindFriendResultListStatus;
        public MyHolder(View itemView) {
            super(itemView);
        }

        @Override
        public void setData2View(int position) {
            SearchResultListBean.ListBean listBean = getItem(position);
            /*
             * avatar
             */
            Glide.with(context).load(ResourcesUtils.getInstance().getImagePath(listBean.picUrl))
                    .apply(new RequestOptions().circleCrop()
                            .placeholder(R.drawable.icon_default_avatar)
                            .error(R.drawable.icon_default_avatar)
                    ).into(ivItemFindFriendResultListAvatar);
            /*
             * name
             */
            tvItemFindFriendResultListName.setText(StringUtils.getInstance().getNotEmptyMsg(listBean.username));
            tvItemFindFriendResultListStatus.setVisibility(View.GONE);
            tvItemFindFriendResultListAdd.setVisibility(View.GONE);
            if (listBean.fstatus == null) {
                tvItemFindFriendResultListAdd.setVisibility(View.VISIBLE);
            } else if (listBean.fstatus.equals("1")) {
                tvItemFindFriendResultListStatus.setVisibility(View.VISIBLE);
                tvItemFindFriendResultListStatus.setText(StringUtils.getInstance().getString(R.string.item_friend_alreaady));
            } else if (listBean.fstatus.equals("0")) {
                tvItemFindFriendResultListStatus.setVisibility(View.VISIBLE);
                tvItemFindFriendResultListStatus.setText(StringUtils.getInstance().getString(R.string.item_friend_request_ing));
            }
            tvItemFindFriendResultListAdd.setOnClickListener(v -> {
                if (onItemClickListener != null) {
                    onItemClickListener.onItemClick(listBean, position, 1);
                }
            });
        }
    }
}
